package o2o.web.actions.order.shop;


import com.jinyou.utils.common.*;
import o2o.business.device.AppDeviceInfoBusiness;
import o2o.cache.agent.ShopAgentRelationMemory;
import o2o.cache.order.OrderInfoImageMemory;
import o2o.cache.order.OrderInfoMemory;
import o2o.cache.order.OrderPayMemory;
import o2o.cache.order.OrderVerifyMemory;
import o2o.cache.order.shop.ShopOrderMemoryMan;
import o2o.cache.order.shop.ShopOrderMemoryMan2;
import o2o.cache.shop.ShopMemory;
import o2o.cache.sys.SysConfigDepositMemory;
import o2o.cache.user.UserInfoMemory;
import o2o.cache.user.UserOnlineImpl;
import o2o.cache.wallet.UserWalletMemory;
import o2o.dao.PO.common.UserType;
import o2o.dao.PO.order.*;
import o2o.dao.PO.shop.FilterConditionUtils;
import o2o.dao.PO.shop.SHOP_IS_INTEGRAL;
import o2o.company.model.ShopInfo;
import o2o.dao.PO.user.UserInfo;
import o2o.dao.PO.wallet.UserWallet;
import o2o.dao.VO.order.OrderInfoImageVO;
import o2o.dao.VO.order.OrderInfoVO;
import o2o.dao.VO.order.OrderInfoVerifyVO;
import o2o.dao.VO.order.OrderVerifyHistoryVO;
import o2o.system.data.SYS_CONFIG_PATH;
import o2o.system.data.SYS_SETTINGS;
import o2o.web.actions.report.ReportAction;
import o2o.web.actions.user.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;


//店铺订单管理
@Controller
public class ShopOrderListController {
    //---------------------------店铺

    /**
     * 新订单（所有未接单订单）   店铺
     */
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/new/list")
    @ResponseBody
    public String order_shop_new_list(String token,
                                      String devJson, // 设备信息
                                      @RequestParam(defaultValue = "0") Integer groupOrder, // 是不是团购订单 0 非团购订单 1 团购订单
                                      Long createTime, Integer size, Integer isLoadMore) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证用户是否有权限
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }
        //获取用户的店铺ID
//        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
//        if (null == shopInfo) {
//            return AjaxResult.errorResult("您还没有开通店铺，请联系客服");
//        }

        // 需要交纳押金的店铺 如果没有缴纳则跳过
        if (null != SYS_SETTINGS.SHOP_MUST_DEPOSIT && 0 == 1 - SYS_SETTINGS.SHOP_MUST_DEPOSIT) {

            // 必须缴纳
            //验证押金金额是否满足
            UserWallet userWallet = UserWalletMemory.getInstance().getWallet(user.getUsername());
            if (null == userWallet) {
                return AjaxResult.errorResult("该账号未缴纳押金，无法获取新订单");
            }
            if (null == userWallet.getDepositMoney() || userWallet.getDepositMoney() <= 0) {
                return AjaxResult.errorResult("该账号未缴纳押金，无法获取新订单！");
            }
            //必须缴纳的押金金额
            Double money = SysConfigDepositMemory.getInstance().getByType(UserType.SHOP_OWNER);
            if (null == money) {
                money = 0d;
            }

            if (JYMathDoubleUtils.sub(userWallet.getDepositMoney(), money) < 0) {
                return AjaxResult.errorResult("该账号缴纳的押金不足，请先缴纳押金");
            }
        }


        if (ValidateUtil.isNotAbsLong(createTime)) {
            createTime = 0l;
        }
        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 20;
        }
        //是否为加载更多  0不是  1市
        if (ValidateUtil.isNotAbsInteger(isLoadMore)) {
            isLoadMore = 0;//默认非加载更多
        }

        //获取该店铺所有未接订单
        List<OrderInfo> list = new ArrayList<OrderInfo>();
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (null != shopInfo) {
            if (ValidateUtil.isNotNull(devJson)) {
                // 处理设备信息
                AppDeviceInfoBusiness.shopAddDevice(shopInfo.getId(), devJson);
            }


            FilterConditionUtils utils = FilterConditionUtils.getInstance().setGroupOrder(groupOrder);
//            list = OrderInfoMemory.getInstance().listOfShopNew(shopInfo.getId(), createTime, size, isLoadMore, utils);
            list = ShopOrderMemoryMan.listOfShopNew(shopInfo.getId(), createTime, size, isLoadMore, utils);
        }

        if (ValidateUtil.isAbsList(list)) {
            List<OrderInfoVO> voList = new ArrayList<OrderInfoVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                OrderInfoVO orderInfoVO = new OrderInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), orderInfoVO, null);
//                    orderInfoVO.setUpdateTime(list.get(i).getUpdateTime());
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
//                    orderInfoVO.setShopImageUrl(Common.imageUrl + orderInfoVO.getShopImageUrl());
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }


                //店铺实际收入金额
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderInfoVO.getOrderNo());
                if (null != orderPayInfo) {
                    orderInfoVO.setShopMoney(orderPayInfo.getShopMoney());
                }


                voList.add(orderInfoVO);
            }

            if (ValidateUtil.isAbsList(voList)) {
                return AjaxResult.successResult(voList.size(), voList);
            }
        }
        return AjaxResult.successResult(0, null);
    }

    //进行中订单
    @RequestMapping(method = RequestMethod.POST, value = {"/shop/order/ing/list", "/group/shop/order/ing/list"})
    @ResponseBody
    public String order_shop_ing_list(String token, Long createTime, Integer size, Integer page, Integer sortType, @RequestParam(defaultValue = "0") Integer groupOrder, Long agentAddressId, Integer isLoadMore) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证用户是否有权限
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }

        //如果createTime是-1  是获取所有进行中订单
        if (null == createTime) {
            createTime = 0l;
        }

        if (null == size) {
            size = 20;
        }

        if (null == isLoadMore) {
            if (createTime > 0) {
                // 老版本的，传了非0时间戳则是加载更多
                isLoadMore = 1;
            } else {
                isLoadMore = 0;
            }
        }

        //获取该店铺所有已接订单
        List<OrderInfo> list = new ArrayList<OrderInfo>();
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        Integer count = 0;
        if (null != shopInfo) {
            FilterConditionUtils utils = FilterConditionUtils.getInstance().setGroupOrder(groupOrder).setAgentAddressId(agentAddressId);
            if (sortType != null || page != null) {
                if (page == null || page <= 0) {
                    page = 1;
                }
                list = ShopOrderMemoryMan.listOfShopIngAll(shopInfo.getId(), shopInfo.getIsSelfPost(), utils);
                if (ValidateUtil.isAbsList(list)) {
                    list.stream().forEach(item -> {
                        if (item.getPreDayNo() == null) {
                            item.setPreDayNo(0);
                        }
                    });
                    if (sortType != null && sortType == 1) {
                        Collections.sort(list, Comparator.comparingInt(OrderInfo::getPreDayNo));
                    } else {
                        Collections.sort(list, Comparator.comparingInt(OrderInfo::getPreDayNo).reversed());
                    }
                    JYPageUtils.PageList pageList = JYPageUtils.getList(list, page, size);
                    if (pageList != null && ValidateUtil.isAbsList(pageList.list)) {
                        list = (List<OrderInfo>) pageList.list;
                        count = pageList.totalCount;
                    }
                }
            } else {
                list = ShopOrderMemoryMan.listOfShopIng(shopInfo.getId(), shopInfo.getIsSelfPost(), createTime, size, isLoadMore, utils);
            }
        }
        if (ValidateUtil.isAbsList(list)) {
            List<OrderInfoVerifyVO> voList = new ArrayList<OrderInfoVerifyVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                OrderInfoVerifyVO orderInfoVO = new OrderInfoVerifyVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), orderInfoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }

                //店铺实际收入金额
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderInfoVO.getOrderNo());
                if (null != orderPayInfo) {
                    orderInfoVO.setShopMoney(orderPayInfo.getShopMoney());
                }

                orderInfoVO.setVerifyCode("");
                voList.add(orderInfoVO);
            }

            if (ValidateUtil.isAbsList(voList)) {
                if (sortType != null || page != null) {
                    return AjaxResult.successResult(voList, count);
                } else {
                    return AjaxResult.successResult(voList.size(), voList);
                }
            }
        }
        return AjaxResult.successResult(null, Long.parseLong(count + ""));
    }

    // 申请退款订单
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/refund/list")
    @ResponseBody
    public String order_shop_refund_list(String token, Integer isLoadMore, Long createTime, Integer size) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证用户是否有权限
//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }


        //如果createTime是-1  是获取所有进行中订单
        if (null == createTime) {
            createTime = 0l;
        }

        if (null == size) {
            size = 20;
        }
        //获取该店铺所有已接订单
        List<OrderInfo> list = new ArrayList<OrderInfo>();
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
//        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername("13122220000");
        if (null != shopInfo) {
//            list = OrderInfoMemory.getInstance().listOfShopIng(shopInfo.getId(), shopInfo.getIsSelfPost(), true, createTime, size);
            list = ShopOrderMemoryMan.listOfShopRefund(shopInfo.getId(), isLoadMore, createTime, size);
        }
//        long nowTime = System.currentTimeMillis();
//        long todayStartTime = nowTime - (nowTime + TimeZone.getDefault().getRawOffset()) % (1000 * 3600 * 24);
        Long todayStartTime = DateUtils.getTodayStartTimestamp();
        if (ValidateUtil.isAbsList(list)) {
            List<OrderInfoVerifyVO> voList = new ArrayList<OrderInfoVerifyVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                // 订单只显示当天的
                if (SYS_SETTINGS.ORDER_ONLY_SHOW_TODAY == 1 && list.get(i).getCreateTime() < todayStartTime) {
                    continue;
                }
                OrderInfoVerifyVO orderInfoVO = new OrderInfoVerifyVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), orderInfoVO);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
//                    orderInfoVO.setShopImageUrl(Common.imageUrl + orderInfoVO.getShopImageUrl());
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }

                //店铺实际收入金额
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderInfoVO.getOrderNo());
                if (null != orderPayInfo) {
                    orderInfoVO.setShopMoney(orderPayInfo.getShopMoney());
                }

                orderInfoVO.setVerifyCode("");
                voList.add(orderInfoVO);
            }

            if (ValidateUtil.isAbsList(voList)) {
                return AjaxResult.successResult(voList.size(), voList);
            }
        }

        return AjaxResult.successResult(0, null);
    }

    //已完成订单
    @RequestMapping(method = RequestMethod.POST, value = {"/shop/order/finish/list", "/shop/order/over/list"})
    @ResponseBody
    public String order_shop_over_list(String token, Long createTime, int size, @RequestParam(defaultValue = "0") Integer groupOrder) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证用户是否有权限
//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }

        if (ValidateUtil.isNotAbsLong(createTime)) {
            createTime = 0l;
        }
        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 20;
        }
        //获取该店铺所有已接订单
        List<OrderInfo> list = new ArrayList<OrderInfo>();
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (null != shopInfo) {
            FilterConditionUtils filterUtils = FilterConditionUtils.getInstance().setGroupOrder(groupOrder);
            // todo zhuwx 直接查数据库
            list = ShopOrderMemoryMan.listOfShopFinish(shopInfo.getId(), shopInfo.getIsSelfPost(), createTime, size, filterUtils);
        }
        if (ValidateUtil.isAbsList(list)) {
            List<OrderInfoVerifyVO> voList = new ArrayList<OrderInfoVerifyVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                OrderInfoVerifyVO orderInfoVO = new OrderInfoVerifyVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), orderInfoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
//                    orderInfoVO.setShopImageUrl(Common.imageUrl + orderInfoVO.getShopImageUrl());
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }

                //店铺实际收入金额
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderInfoVO.getOrderNo());
                if (null != orderPayInfo) {
                    orderInfoVO.setShopMoney(orderPayInfo.getShopMoney());
                }

                orderInfoVO.setVerifyCode("");
                voList.add(orderInfoVO);
            }

            if (ValidateUtil.isAbsList(voList)) {
                return AjaxResult.successResult(voList.size(), voList);
            }
        }

        return AjaxResult.successResult(0, null);
    }

    //已完成订单
    @RequestMapping(method = RequestMethod.POST, value = {"/group/shop/order/finish/list"})
    @ResponseBody
    public String group_order_shop__list(String token, Long createTime, int size, @RequestParam(defaultValue = "0") Integer groupOrder, Long startTime, Long endTime) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        //验证用户是否有权限
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }
        if (ValidateUtil.isNotAbsLong(createTime)) {
            createTime = 0l;
        }
        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 20;
        }
        //获取该店铺所有已接订单
        List<OrderInfo> list = new ArrayList<OrderInfo>();
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (null != shopInfo) {
            FilterConditionUtils filterUtils = FilterConditionUtils.getInstance().setGroupOrder(groupOrder);
            filterUtils.setStartTime(startTime).setEndTime(endTime);
            if (groupOrder == 1) { // 团购订单
                list = ShopOrderMemoryMan.listOfGroupShopFinish(shopInfo.getId(), shopInfo.getIsSelfPost(), createTime, size, filterUtils);
            } else {
                list = ShopOrderMemoryMan.listOfShopFinish(shopInfo.getId(), shopInfo.getIsSelfPost(), createTime, size, filterUtils);
            }
        }
        if (ValidateUtil.isAbsList(list)) {
            List<OrderInfoVerifyVO> voList = new ArrayList<OrderInfoVerifyVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                OrderInfoVerifyVO orderInfoVO = new OrderInfoVerifyVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), orderInfoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }
                //店铺实际收入金额
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderInfoVO.getOrderNo());
                if (null != orderPayInfo) {
                    orderInfoVO.setShopMoney(orderPayInfo.getShopMoney());
                }
                orderInfoVO.setVerifyCode("");
                voList.add(orderInfoVO);
            }

            if (ValidateUtil.isAbsList(voList)) {
                return AjaxResult.successResult(voList.size(), voList);
            }
        }
        return AjaxResult.successResult(0, null);
    }


    //已处理（所有已接订单）  店铺
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/list")
    @ResponseBody
    public String order_shop_do_list(String token, Long createTime, @RequestParam(defaultValue = "0") Integer groupOrder, Integer size, Integer isLoadMore) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证用户是否有权限
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }

//        if (ValidateUtil.isNotAbsLong(createTime)) {
//            createTime = 0l;
//        }

        //如果createTime是-1  是获取所有进行中订单
        if (null == createTime) {
            createTime = 0l;
        }

        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 20;
        }

        if (null == isLoadMore) {
            if (createTime > 0) {
                // 老版本的，传了非0时间戳则是加载更多
                isLoadMore = 1;
            } else {
                isLoadMore = 0;
            }
        }

        //获取该店铺所有已接订单
        List<OrderInfo> list = new ArrayList<OrderInfo>();
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (null != shopInfo) {
            FilterConditionUtils utils = FilterConditionUtils.getInstance().setGroupOrder(groupOrder);
            list = ShopOrderMemoryMan.listOfShopDo(shopInfo.getId(), false, null, null, createTime, size, utils);
        }
        if (ValidateUtil.isAbsList(list)) {
            List<OrderInfoVerifyVO> voList = new ArrayList<OrderInfoVerifyVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                OrderInfoVerifyVO orderInfoVO = new OrderInfoVerifyVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), orderInfoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
//                    orderInfoVO.setShopImageUrl(Common.imageUrl + orderInfoVO.getShopImageUrl());
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }

                //店铺实际收入金额
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderInfoVO.getOrderNo());
                if (null != orderPayInfo) {
                    orderInfoVO.setShopMoney(orderPayInfo.getShopMoney());
                }

                orderInfoVO.setVerifyCode("");
                voList.add(orderInfoVO);
            }

            if (ValidateUtil.isAbsList(voList)) {
                return AjaxResult.successResult(voList.size(), voList);
            }
        }

        return AjaxResult.successResult(0, null);
    }

    //商户已确认接单，未进行下一步操作的订单（仅此一个状态的订单/商城普通订单）  pc
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/sure/list")
    @ResponseBody
    public String order_shop_sure_list(String token, Long createTime, Integer size, Integer isLoadMore) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

//        验证用户是否有权限
//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }

        if (ValidateUtil.isNotAbsLong(createTime)) {
            createTime = 0l;
        }
        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 20;
        }
        //获取该店铺所有已接订单
        List<OrderInfo> list = new ArrayList<OrderInfo>();
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (null != shopInfo) {
            list = ShopOrderMemoryMan.listOfShopSure(shopInfo.getId(), ORDER_TYPE.SHOP_GOODS, createTime, size, isLoadMore);
        }


//        List<String> listOrder = null;
//        if (null != shopInfo) {
//            listOrder = OrderInfoMemory.getInstance().listOfShopId(shopInfo.getId());
//        }
//
//        List<OrderInfo> list1 = new ArrayList<OrderInfo>();
//        if (ValidateUtil.isAbsList(listOrder)) {
//
//            // 去重
//            HashSet<String> orderNoSet = new HashSet<>();
//            if (ValidateUtil.isAbsList(list)) {
//                for (int i = 0; i < list.size(); i++) {
//                    if (null == list.get(i) || ValidateUtil.isNull(list.get(i).getOrderNo())) {
//                        continue;
//                    }
//                    orderNoSet.add(list.get(i).getOrderNo());
//                }
//            }
//
//            for (String str : listOrder) {
//                if (ValidateUtil.isNull(str)) {
//                    continue;
//                }
//                if (orderNoSet.contains(str)) {
//                    continue;
//                }
//                OrderInfo orderInfo = OrderInfoMemory.getInstance().getOrderInfo(str);
//                list1.add(orderInfo);
//            }
//        }
//        if (ValidateUtil.isAbsList(list1)) {
//            list1 = list1.stream().filter(l -> {
//                if (0 != l.getOrderStatus() - ORDER_STATUS.POSTMAN_SURE && 0 != l.getOrderStatus() - ORDER_STATUS.POSTMAN_DAODIAN) {
//                    return false;
//                }
//                long nowTime = System.currentTimeMillis();
//                long todayStartTime = nowTime - (nowTime + TimeZone.getDefault().getRawOffset()) % (1000 * 3600 * 24);
//                if (SYS_SETTINGS.ORDER_ONLY_SHOW_TODAY == 0 || (SYS_SETTINGS.ORDER_ONLY_SHOW_TODAY == 1 && l.getCreateTime() > todayStartTime)) {
//                    return true;
//                }
//                return false;
//            }).collect(Collectors.toList());
//
//            list.addAll(list1);
//        }
        if (ValidateUtil.isAbsList(list)) {
            Long todayStartTime = DateUtils.getTodayStartTimestamp();
            List<OrderInfoVerifyVO> voList = new ArrayList<OrderInfoVerifyVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }

                // 订单只显示当天的
                if (SYS_SETTINGS.ORDER_ONLY_SHOW_TODAY == 1 && list.get(i).getCreateTime() < todayStartTime) {
                    continue;
                }
                OrderInfoVerifyVO orderInfoVO = new OrderInfoVerifyVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), orderInfoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
//                    orderInfoVO.setShopImageUrl(Common.imageUrl + orderInfoVO.getShopImageUrl());
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }

                //店铺实际收入金额
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderInfoVO.getOrderNo());
                if (null != orderPayInfo) {
                    orderInfoVO.setShopMoney(orderPayInfo.getShopMoney());
                }

                orderInfoVO.setVerifyCode("");
                voList.add(orderInfoVO);
            }

            if (ValidateUtil.isAbsList(voList)) {
                return AjaxResult.successResult(voList.size(), voList);
            }
        }

        return AjaxResult.successResult(0, null);
    }

    // 未分配店铺的订单(等我5分钟)
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/grab/ing/list")
    @ResponseBody
    public String order_shop_new_grap_list(String token, Integer orderType, Long createTime, int size, Integer isLoadMore) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //是否有权限抢单
//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有权限");
        }

        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (null == shopInfo) {
            return AjaxResult.errorResult("您不是店主无法 操作");
        }
        if (ValidateUtil.isNull(shopInfo.getCity())) {
            return AjaxResult.errorResult("您的店铺信息不完整（无城市信息），请先填写完整");
        }
        if (ValidateUtil.isNotAbsInteger(shopInfo.getIsWork())) {
            return AjaxResult.errorResult("您无法接单，请先上班");
        }
        if (0 == shopInfo.getIsWork()) {
            return AjaxResult.errorResult("请先上班");
        }

        //是否为加载更多，0不是，1是
        if (ValidateUtil.isNotAbsInteger(isLoadMore)) {
            isLoadMore = 0;
        }

        if (ValidateUtil.isNotAbsLong(createTime)) {
            createTime = 0l;
        }
        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 20;
        }

        // 获取店铺的商圈
        Long agentId = ShopAgentRelationMemory.getInstance().getAgentByShopId(shopInfo.getId());
        //无最新指定订单，返回待抢订单
        //获取该城市订单
        List<OrderInfo> orderList = ShopOrderMemoryMan.listOfNoShopSureInAgent(agentId, createTime, size, isLoadMore, orderType);
        if (ValidateUtil.isAbsList(orderList)) {
            List<OrderInfoVO> orderInfoVOList = new ArrayList<OrderInfoVO>();
            for (int i = 0; i < orderList.size(); i++) {
                if (null == orderList.get(i)) {
                    continue;
                }

                OrderInfoVO orderInfoVO = new OrderInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(orderList.get(i), orderInfoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNull(orderInfoVO.getShopImageUrl()) && ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
//                    orderInfoVO.setShopImageUrl(Common.imageUrl + orderInfoVO.getShopImageUrl());
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }

                //店铺实际收入金额
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderInfoVO.getOrderNo());
                if (null != orderPayInfo) {
                    orderInfoVO.setShopMoney(orderPayInfo.getShopMoney());
                }

                orderInfoVOList.add(orderInfoVO);
            }
            return AjaxResult.successResult(orderInfoVOList.size(), orderInfoVOList);
        }

        return AjaxResult.successResult(0, null);
    }

    //订单查询
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/search/list")
    @ResponseBody
    public String order_shop_list(String token, Integer orderType, Long createTime, Integer size,
                                  Long shopId, String phone, String address, String name, String orderNo, Integer orderStatus,
                                  Long startTime, Long endTime, Integer isExcel) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证用户是否有权限
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }

        if (ValidateUtil.isNotID(shopId)) {
            return AjaxResult.errorResult("店铺ID不能为空");
        }

        ShopInfo shopInfo = ShopMemory.getInstance().getShopById(shopId);
        if (null == shopInfo) {
            return AjaxResult.errorResult("获取店铺信息失败，请稍后再试");
        }

        if (ValidateUtil.isNotAbsLong(createTime)) {
            createTime = 0l;
        }
        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 10;
        }
        if (ValidateUtil.isNotAbsInteger(orderType)) {
            orderType = null;
        }
        if (null == isExcel) {
            isExcel = 0;
        }

        List<OrderInfo> list = ShopOrderMemoryMan.listOfShop(shopId, orderType, phone, address, name, orderNo, orderStatus, startTime, endTime, createTime, size, 0, isExcel);

        if (ValidateUtil.isAbsList(list)) {
            List<OrderInfoVO> voList = new ArrayList<OrderInfoVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                OrderInfoVO orderInfoVO = new OrderInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), orderInfoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
//                    orderInfoVO.setShopImageUrl(Common.imageUrl + orderInfoVO.getShopImageUrl());
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }

                //店铺实际收入金额
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderInfoVO.getOrderNo());
                if (null != orderPayInfo) {
                    orderInfoVO.setShopMoney(orderPayInfo.getShopMoney());
                }

                voList.add(orderInfoVO);
            }
            if (isExcel == 1) {
                // 导出excel
                String downloadUrl = ReportAction.generateOrderExcel(voList, null);
                if (ValidateUtil.isNotNull(downloadUrl)) {
                    String url = SYS_CONFIG_PATH.IMAGE_BASE_URL + downloadUrl;
                    return AjaxResult.successResult(url);
                }
            } else {
                if (ValidateUtil.isAbsList(voList)) {
                    return AjaxResult.successResult(voList.size(), voList);
                }
            }
        }
        return AjaxResult.successResult(0, 0, null);
    }

    //---------------------------------

    /**
     * 积分商城订单
     */
    @RequestMapping(method = RequestMethod.POST, value = "/integral/order/new/list")
    @ResponseBody
    public String order_integral_shop_new_list(String token, Integer page, Integer size) {
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        //验证用户是否有权限
//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }
        List<ShopInfo> shopInfoList = ShopMemory.getInstance().listOfIntegralShop(SHOP_IS_INTEGRAL.HAS_INTEGRAL_SHOP);
        if (!ValidateUtil.isAbsList(shopInfoList)) {
            return AjaxResult.errorResult("未查询到商城订单");
        }
        // 默认第一个
        ShopInfo shopInfo = shopInfoList.get(0);
        if (null == shopInfo) {
            return AjaxResult.errorResult("店铺不存在");
        }
        List<OrderInfo> orderInfoList = ShopOrderMemoryMan.listOfOrderType(shopInfo.getId(), ORDER_TYPE.INTEGRAL_ORDER, null, null);
        List<OrderInfo> list = new ArrayList<>();
        if (ValidateUtil.isAbsList(orderInfoList)) {
            for (OrderInfo info : orderInfoList) {
                if (info.getOrderStatus() - ORDER_STATUS.SUBMIT == 0) {
                    list.add(info);
                }
            }
        }

        if (ValidateUtil.isAbsList(list)) {
            List<OrderInfoVO> voList = new ArrayList<OrderInfoVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                OrderInfoVO orderInfoVO = new OrderInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), orderInfoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }
                voList.add(orderInfoVO);
            }
            if (ValidateUtil.isAbsList(voList)) {
                JYPageUtils.PageList pageList = JYPageUtils.getList(voList, page, size);
                return AjaxResult.successResult(pageList.totalCount, pageList.list.size(), pageList.list);
            }
        }
        return AjaxResult.successResult(0, 0, null);
    }

    //----

    /**
     * 店铺查看预约订单
     */
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/appointment/list")
    @ResponseBody
    public String order_shop_appoint_list(String token,
                                          Long startTime, Long endTime,//特定时间内的  明天，三天内。。。
                                          Long createTime, Integer size) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证用户是否有权限
//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }
        //获取该店铺所有已接订单
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (null == shopInfo) {
            return AjaxResult.errorResult("您不是店主");
        }

        if (ValidateUtil.isNotAbsLong(createTime)) {
            createTime = 0l;
        }
        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 20;
        }

        //获取订单
        List<OrderInfo> list = ShopOrderMemoryMan.listOfShopDo(shopInfo.getId(),
                true,
                startTime, endTime,
                createTime, size, null);
        if (ValidateUtil.isAbsList(list)) {
            List<OrderInfoVerifyVO> voList = new ArrayList<OrderInfoVerifyVO>();
            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }
                OrderInfoVerifyVO orderInfoVO = new OrderInfoVerifyVO();
                try {
                    ObjectUtils.copyPropertiesExclude(list.get(i), orderInfoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                if (null == orderInfoVO) {
                    continue;
                }
                if (ValidateUtil.isNotNetUrl(orderInfoVO.getShopImageUrl())) {
                    orderInfoVO.setShopImageUrl(SYS_CONFIG_PATH.IMAGE_BASE_URL + orderInfoVO.getShopImageUrl());
                }

                //店铺实际收入金额
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(orderInfoVO.getOrderNo());
                if (null != orderPayInfo) {
                    orderInfoVO.setShopMoney(orderPayInfo.getShopMoney());
                }

                orderInfoVO.setVerifyCode("");
                voList.add(orderInfoVO);
            }

            if (ValidateUtil.isAbsList(voList)) {
                return AjaxResult.successResult(voList.size(), voList);
            }
        }

        return AjaxResult.successResult(0, null);
    }

    //--------------好管家

    /**
     * 商家获取新订单(好管家)
     */
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/all/type/new/list")
    @ResponseBody
    public String order_shop_new_type_list(String token, Integer orderType, Long createTime, Integer size, Integer isLoadMore) {
        if (ValidateUtil.isNotAbsLong(createTime)) {
            createTime = 0l;
        }
        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 20;
        }

        //店铺所在商圈
        //店铺能看到的维修订单
        //店铺的购物订单


        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证用户是否有权限
//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }

        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        List<OrderInfo> list = new ArrayList<>();
        // 筛选购物和租赁新订单
        List<OrderInfo> lists = OrderInfoMemory.getInstance().listOfOrderInfo();
        if (null != lists && lists.size() > 0) {
            for (int i = 0; i < lists.size(); i++) {
                if (null == lists.get(i)) {
                    continue;
                }
                // 判断订单状态为新订单
                if (ORDER_STATUS.PAYED == lists.get(i).getOrderStatus()) {
                    // 属于本店铺（token）的订单
//                    if (null != shopInfo && shopInfo.getId() == lists.get(i).getShopId()) {
                    if (null != shopInfo && 0 == shopInfo.getId() - lists.get(i).getShopId()) {
                        list.add(lists.get(i));
                    }
                }
            }
        }
        // 获取维修订单和救援订单
        Long agentId = ShopAgentRelationMemory.getInstance().getAgentByShopId(shopInfo.getId());
        List<OrderInfo> lis = ShopOrderMemoryMan2.listOfAppointedRepairOrderList(agentId);

        // 获取订单类型
        List<OrderInfo> infoList = new ArrayList<>();
        if (null != orderType) {
            if (null != list && list.size() > 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (null == list.get(i)) {
                        continue;
                    }
                    if (0 == list.get(i).getOrderType() - orderType) {
                        infoList.add(list.get(i));
                    }
                }
            }
        } else {
            infoList.addAll(list);
        }
        //需不需要判断时间戳
        Boolean flag = false;
        if (null != createTime && createTime > 0) {
            flag = true;
        }
        if (size <= 0) {
            size = 20;
        }
        List<OrderInfo> reList = new ArrayList<OrderInfo>();
        if (null != infoList && infoList.size() > 0) {
            List<OrderInfo> orderInfoList = new ArrayList<OrderInfo>();
            for (int i = 0; i < infoList.size(); i++) {
                if (null == infoList.get(i)) {
                    continue;
                }
                if (flag) {//需要判断时间戳
                    if (0 == 1 - isLoadMore) {//加载更多
                        if (infoList.get(i).getCreateTime() < createTime) { // 下一页
                            orderInfoList.add(infoList.get(i));
                        }
                    } else {
                        continue;
                    }
                } else {
                    orderInfoList.add(infoList.get(i));
                }
            }
            //排序订单，返回前size条
            JYListSort.sortDesc(orderInfoList, "createTime");
            for (int i = 0; i < orderInfoList.size(); i++) {
                if (i < size) {
                    reList.add(orderInfoList.get(i));
                }
            }
        }
        //订单设置
        List<OrderInfoVO> infoVOList = new ArrayList<>();
        OrderInfoVO infoVO = null;
        if (null != reList && reList.size() > 0) {
            for (int i = 0; i < reList.size(); i++) {
                if (null == reList.get(i)) {
                    continue;
                }
                //拷贝订单
                infoVO = new OrderInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(reList.get(i), infoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                //获取相关图片
                List<OrderInfoImage> imageList = OrderInfoImageMemory.getInstance().listOfOrderNo(reList.get(i).getOrderNo());
                List<OrderInfoImageVO> imageVOList = new ArrayList<>();
                //遍历
                if (null != imageList && imageList.size() > 0) {
                    for (int j = 0; j < imageList.size(); j++) {
                        if (null == imageList.get(j)) {
                            continue;
                        }
                        //拷贝图片
                        OrderInfoImageVO imageVO = new OrderInfoImageVO();
                        try {
                            ObjectUtils.copyPropertiesExclude(imageList.get(j), imageVO, null);
                        } catch (Exception e) {
                            e.printStackTrace();
                            continue;
                        }
                        imageVOList.add(imageVO);
                    }
                    //设置图片信息
                    infoVO.setImageList(imageVOList);
                }
                infoVOList.add(infoVO);
            }
        }
        if (ValidateUtil.isAbsList(infoVOList)) {
            return AjaxResult.successResult(infoVOList.size(), infoVOList);
        }
        return AjaxResult.successResult(0, null);
    }

    //获取已处理的订单(好管家pc)
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/all/type/sure/list")
    @ResponseBody
    public String order_shop_all_type_sure_list(String token, Integer orderType, Long createTime, Integer
            size, Integer isLoadMore) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        //验证用户是否有权限
//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }
        // 获取订单
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
//        List<OrderInfo> lists = OrderInfoMemory.getInstance().listOfShopSureOrder(orderType, shopInfo.getId(), createTime, size, isLoadMore);
        List<OrderInfo> lists = ShopOrderMemoryMan.listOfShopSure(shopInfo.getId(), orderType, createTime, size, isLoadMore);
        //订单设置
        List<OrderInfoVO> infoVOList = new ArrayList<>();
        OrderInfoVO infoVO = null;
        if (null != lists && lists.size() > 0) {
            for (int i = 0; i < lists.size(); i++) {
                if (null == lists.get(i)) {
                    continue;
                }
                //拷贝订单
                infoVO = new OrderInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(lists.get(i), infoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                //获取相关图片
                List<OrderInfoImage> imageList = OrderInfoImageMemory.getInstance().listOfOrderNo(lists.get(i).getOrderNo());
                List<OrderInfoImageVO> imageVOList = new ArrayList<>();
                //遍历
                if (null != imageList && imageList.size() > 0) {
                    for (int j = 0; j < imageList.size(); j++) {
                        if (null == lists.get(j)) {
                            continue;
                        }
                        //拷贝图片
                        OrderInfoImageVO imageVO = new OrderInfoImageVO();
                        try {
                            ObjectUtils.copyPropertiesExclude(imageList.get(j), imageVO, null);
                        } catch (Exception e) {
                            e.printStackTrace();
                            continue;
                        }
                        imageVOList.add(imageVO);
                    }
                    //设置图片信息
                    infoVO.setImageList(imageVOList);
                }
                OrderPayInfo orderPayInfo = OrderPayMemory.getInstance().get(infoVO.getOrderNo());
                if (null != orderPayInfo) {
                    infoVO.setShopMoney(orderPayInfo.getShopMoney());
                }
                infoVOList.add(infoVO);
            }
        }
        if (ValidateUtil.isAbsList(infoVOList)) {
            return AjaxResult.successResult(infoVOList.size(), infoVOList);
        }
        return AjaxResult.successResult(0, null);
    }

    //获取已提货订单/商家 (好管家pc)
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/all/type/over/list")
    @ResponseBody
    public String order_shop_all_type_done_list(String token, Integer orderType, Long createTime, Integer
            size, Integer isLoadMore) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        //验证用户是否有权限
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
//        if (!User.hasShopAuth(user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }
        // 获取订单
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        List<OrderInfo> lists = ShopOrderMemoryMan2.listOfShopOverOrder(orderType, shopInfo.getId(), createTime, size, isLoadMore);
        //订单设置
        List<OrderInfoVO> infoVOList = new ArrayList<>();
        OrderInfoVO infoVO = null;
        if (null != lists && lists.size() > 0) {
            for (int i = 0; i < lists.size(); i++) {
                if (null == lists.get(i)) {
                    continue;
                }
                //拷贝订单
                infoVO = new OrderInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(lists.get(i), infoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                //获取相关图片
                List<OrderInfoImage> imageList = OrderInfoImageMemory.getInstance().listOfOrderNo(lists.get(i).getOrderNo());
                List<OrderInfoImageVO> imageVOList = new ArrayList<>();
                //遍历
                if (null != imageList && imageList.size() > 0) {
                    for (int j = 0; j < imageList.size(); j++) {
                        if (null == lists.get(j)) {
                            continue;
                        }
                        //拷贝图片
                        OrderInfoImageVO imageVO = new OrderInfoImageVO();
                        try {
                            ObjectUtils.copyPropertiesExclude(imageList.get(j), imageVO, null);
                        } catch (Exception e) {
                            e.printStackTrace();
                            continue;
                        }
                        imageVOList.add(imageVO);
                    }
                    //设置图片信息
                    infoVO.setImageList(imageVOList);
                }
                infoVOList.add(infoVO);
            }
        }
        if (ValidateUtil.isAbsList(infoVOList)) {
            return AjaxResult.successResult(infoVOList.size(), infoVOList);
        }
        return AjaxResult.successResult(0, null);
    }

    //获取进行中所有订单/商家(好管家)
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/type/ing/list")
    @ResponseBody
    public String order_type_shop_ing_list(String token, Integer orderType, Long createTime, Integer size, Integer
            isLoadMore) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
        //验证用户是否有权限
//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }
        // 获取订单
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        List<OrderInfo> lists = ShopOrderMemoryMan2.listOfShopIngOrder(orderType, shopInfo.getId(), createTime, size, isLoadMore);
        //订单设置
        List<OrderInfoVO> infoVOList = new ArrayList<>();
        OrderInfoVO infoVO = null;
        if (null != lists && lists.size() > 0) {
            for (int i = 0; i < lists.size(); i++) {
                if (null == lists.get(i)) {
                    continue;
                }
                //拷贝订单
                infoVO = new OrderInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(lists.get(i), infoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                //获取相关图片
                List<OrderInfoImage> imageList = OrderInfoImageMemory.getInstance().listOfOrderNo(lists.get(i).getOrderNo());
                List<OrderInfoImageVO> imageVOList = new ArrayList<>();
                //遍历
                if (null != imageList && imageList.size() > 0) {
                    for (int j = 0; j < imageList.size(); j++) {
                        if (null == lists.get(j)) {
                            continue;
                        }
                        //拷贝图片
                        OrderInfoImageVO imageVO = new OrderInfoImageVO();
                        try {
                            ObjectUtils.copyPropertiesExclude(imageList.get(j), imageVO, null);
                        } catch (Exception e) {
                            e.printStackTrace();
                            continue;
                        }
                        imageVOList.add(imageVO);
                    }
                    //设置图片信息
                    infoVO.setImageList(imageVOList);
                }
                infoVOList.add(infoVO);
            }
        }
        if (ValidateUtil.isAbsList(infoVOList)) {
            return AjaxResult.successResult(infoVOList.size(), infoVOList);
        }
        return AjaxResult.successResult(0, null);
    }

    //获取所有已完成订单/商家(好管家)
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/type/finish/list")
    @ResponseBody
    public String order_type_shop_over_list(String token, Integer orderType, Long createTime, Integer size, Integer
            isLoadMore) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

        //验证用户是否有权限
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
//        if (!User.hasShopAuth(user.getUsername(),user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }
        // 获取订单
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        List<OrderInfo> lists = ShopOrderMemoryMan2.listOfShopFinishOrder(orderType, shopInfo.getId(), createTime, size, isLoadMore);

        //订单设置
        List<OrderInfoVO> infoVOList = new ArrayList<>();
        OrderInfoVO infoVO = null;
        if (null != lists && lists.size() > 0) {
            for (int i = 0; i < lists.size(); i++) {
                if (null == lists.get(i)) {
                    continue;
                }
                //拷贝订单
                infoVO = new OrderInfoVO();
                try {
                    ObjectUtils.copyPropertiesExclude(lists.get(i), infoVO, null);
                } catch (Exception e) {
                    e.printStackTrace();
                    continue;
                }
                //获取相关图片
                List<OrderInfoImage> imageList = OrderInfoImageMemory.getInstance().listOfOrderNo(lists.get(i).getOrderNo());
                List<OrderInfoImageVO> imageVOList = new ArrayList<>();
                //遍历
                if (null != imageList && imageList.size() > 0) {
                    for (int j = 0; j < imageList.size(); j++) {
                        if (null == lists.get(j)) {
                            continue;
                        }
                        //拷贝图片
                        OrderInfoImageVO imageVO = new OrderInfoImageVO();
                        try {
                            ObjectUtils.copyPropertiesExclude(imageList.get(j), imageVO, null);
                        } catch (Exception e) {
                            e.printStackTrace();
                            continue;
                        }
                        imageVOList.add(imageVO);
                    }
                    //设置图片信息
                    infoVO.setImageList(imageVOList);
                }
                infoVOList.add(infoVO);
            }
        }
        if (ValidateUtil.isAbsList(infoVOList)) {
            return AjaxResult.successResult(infoVOList.size(), infoVOList);
        }
        return AjaxResult.successResult(0, null);
    }


    //--------------验证记录

    /**
     * 查看验证记录
     */
    @RequestMapping(method = RequestMethod.POST, value = "/order/shop/verify/history")
    @ResponseBody
    public String order_shop_verify(String token, Long createTime, Integer size) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }

//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有店铺操作权限");
        }

        if (ValidateUtil.isNotAbsLong(createTime)) {
            createTime = 0l;
        }
        if (ValidateUtil.isNotAbsInteger(size)) {
            size = 20;
        }


        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (null == shopInfo) {
            return AjaxResult.errorResult("您不是店主，不能查看");
        }

        List<OrderVerifyHistory> list = OrderVerifyMemory.getInstance().get(shopInfo.getId());
        if (ValidateUtil.isAbsList(list)) {

            List<OrderVerifyHistory> tmpList = new ArrayList<OrderVerifyHistory>();

            for (int i = 0; i < list.size(); i++) {
                if (null == list.get(i)) {
                    continue;
                }

                if (createTime > 0 && list.get(i).getCreateTime() >= createTime) {
                    continue;
                }
                tmpList.add(list.get(i));

            }
            if (ValidateUtil.isAbsList(tmpList)) {
                //排序订单
                JYListSort.sort(tmpList, "createTime");

                //返回前size条
                List<OrderVerifyHistoryVO> voList = new ArrayList<OrderVerifyHistoryVO>();
                for (int i = 0; i < tmpList.size(); i++) {
                    if (i >= size) {
                        break;
                    }

                    OrderVerifyHistoryVO verifyVO = new OrderVerifyHistoryVO();
                    try {
                        ObjectUtils.copyPropertiesExclude(list.get(i), verifyVO, null);
                    } catch (Exception e) {
                        e.printStackTrace();
                        continue;
                    }
                    if (null == verifyVO) {
                        continue;
                    }

                    UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(verifyVO.getVerifyUsername());
                    if (null == userInfo) {
                        continue;
                    }
                    verifyVO.setVerifyName(userInfo.getName());
                    verifyVO.setVerifyImageUrl(userInfo.getSignPhoto());
                    verifyVO.setVerifyPhone(userInfo.getTelPhone());
                    voList.add(verifyVO);
                }


                if (ValidateUtil.isAbsList(voList)) {
                    return AjaxResult.successResult(voList.size(), voList);
                }
            }


        }


        return AjaxResult.successResult(0, null);
    }

    //---------------团购订单



    //----------------------------------------

    /**
     * 商户分页获取所有的到店支付订单信息（紫燕） 没人调用 暂时废弃
     *
     * @param token
     * @param orderType
     * @param strTime
     * @param endTime
     * @return 商户分页获取所有的到店支付订单信息（紫燕） 没人调用 暂时废弃
     */
    @RequestMapping(method = RequestMethod.POST, value = "/shop/order/list/by/orderType")
    @ResponseBody
    public String getOrderListByOrderType(String token, Integer orderType, Long strTime, Long endTime) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));
        if (user == null) {
            return AjaxResult.errorLogoutResult();
        }
//        if (!User.hasShopAuth(user.getUserType())) {
        if (!User.hasShopAuth(user.getUsername(), user.getUserType())) {
            return AjaxResult.errorResult("您没有权限访问");
        }
        if (ValidateUtil.isNotAbsInteger(orderType)) {
//            orderType = ORDER_TYPE.TO_SHOP_PAYMENT;
        }
        ShopInfo shopInfo = ShopMemory.getInstance().getShopByUsername(user.getUsername());
        if (shopInfo == null) {
            return AjaxResult.errorResult("请核实店铺信息");
        }
        List<OrderInfo> listOrderInfoVO = ShopOrderMemoryMan.listOfOrderType(shopInfo.getId(), null, strTime, endTime);
        List<OrderInfo> list = new ArrayList<>();
        if (ValidateUtil.isAbsList(listOrderInfoVO)) {
            for (OrderInfo orderInfo : listOrderInfoVO) {
                if (orderInfo.getOrderType() == orderType && 1 - orderInfo.getIsPaid() == 0) {
                    list.add(orderInfo);
                }
            }
        }
        if (ValidateUtil.isAbsList(list)) {
            Collections.sort(list, new Comparator<OrderInfo>() {
                @Override
                public int compare(OrderInfo o1, OrderInfo o2) {
                    return (int) (o2.getCreateTime() - o2.getCreateTime());
                }
            });
            return AjaxResult.successResult(list.size(), list);
        }
        return AjaxResult.successResult(0, null);
    }

}
